<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>体温登记</title>

    <link href="assets/bootstrap-3.3.7/css/bootstrap.css" rel="stylesheet">


</head>
<body background="images/bg-img.png">
<div class="container" style="margin-top: 150px">
    <div class="panel panel-success">
        <div class="panel-heading">
            <p align="center"><strong>体温登记表</strong></p>
        </div>
        <div class="panel-body">
            <div class="row">
                <div class="col-lg-12">
                    <div class="form-group">
                        <input id="tempid" type="text" style="display: none">
                        <label>今日体温：</label>
                        <input class="form-control" placeholder="36.7" id="temp">
                        <p class="help-block">务必填写真实体温</p>
                    </div>
                    <div align="right">
                        <button type="submit" class="btn btn-default" onclick="saveTemp()">提交</button>
                    </div>
                </div>
            </div>
            <!-- /.row (nested) -->
        </div>
        <!-- /.panel-body -->
        <div class="panel-footer">
            2020年6月5日
        </div>
    </div>
</div>

</body>
<script type="text/javascript" src="assets/jquery.min.js"></script>
<script type="text/javascript" src="assets/layui/layui.js"></script>
<script src="assets/bootstrap-3.3.7/js/bootstrap.js"></script>
<script>

    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;


    });
    // $("#temp").attr("readOnly",true);

    // 获取已经填写的信息
    $.ajax({
        type: "get",
        contentType: "application/x-www-form-urlencoded",
        url: "/api/v1/temp/gettemp",
        data: {},
        dataType: "json",
        success: function (data) {

            if (data.resultTypeEnum == 200) {
                $("#temp").val(data.message.temperature)
                $("#tempid").val(data.message.id)
            } else {
                layer.msg(data.message, {icon: 2});
            }

        }
    })

    // 非时间结点内不可提交
    getHour()

    //获取时间
    function getHour() {
        var time = new Date();
        var timehour = +time.getHours()
        // console.log(timehour)
        if (timehour > 21 || timehour < 6) {

            setReadOnly()
        }

    }

    //判断时间结点并设置只读
    function setReadOnly() {
        $("#temp").val("不在提交时间内！")
        $("#temp").attr("readOnly", true);
    }

    function saveTemp() {
        var temp = $("#temp").val()
        var tempid = $("#tempid").val()
        if (isNaN(temp)) {
            layer.msg("格式错误！", {icon: 2})
        }

        $.ajax({
            type: "get",
            contentType: "application/x-www-form-urlencoded",
            url: "/api/v1/temp/save",
            data: {
                "temp": temp,
                "tempid": tempid,
            },
            dataType: "json",
            success: function (data) {

                if (data.resultTypeEnum == 200) {
                    layer.msg(data.message, {icon: 1});

                } else {
                    layer.msg(data.message, {icon: 2});
                }

            }
        })
    }
</script>
</html>